home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletpalette.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  3.9 KB  |  223 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletdefs.h"
  6. #include "appletquickdraw.h"
  7. #include "appletstrings.h"
  8. #include "appletkb.h"
  9. #include "appletmemory.h"
  10. #include "appletmouse.h"
  11. #include "appletpalette.h"
  12.  
  13.  
  14.  
  15.  
  16.  
  17. #define drawinset 3
  18. #define ctperline 2
  19. #define heightpaletteicon (heightsmallicon + 6)
  20. #define widthpaletteicon (widthsmallicon + 6)
  21. #define breakpixels 4
  22.  
  23.  
  24.  
  25. static void geticonrect (hdlpaletterecord hpal, short iconnum, Rect *ricon) {
  26.     
  27.     /*
  28.     iconnum is 0-based.
  29.     */
  30.     
  31.     Rect rpal = (**hpal).r;
  32.     short extrapixels = 0;
  33.     Rect r;
  34.     short lnum;
  35.     short i;
  36.     
  37.     for (i = 0; i < iconnum; i++) {
  38.     
  39.         if ((**hpal).item [i].breakafter)
  40.             extrapixels += breakpixels;
  41.         } /*for*/
  42.     
  43.     lnum = (iconnum / ctperline);
  44.     
  45.     r.top = rpal.top + drawinset + (lnum * (heightpaletteicon - 1)) + extrapixels;
  46.     
  47.     r.bottom = r.top + heightpaletteicon;
  48.     
  49.     r.left = rpal.left + drawinset;
  50.     
  51.     if (iconnum % 2)
  52.         r.left += widthpaletteicon - 1;
  53.     
  54.     r.right = r.left + widthpaletteicon;
  55.     
  56.     *ricon = r;
  57.     } /*geticonrect*/
  58.     
  59.     
  60. hdlpaletterecord newpalette (WindowPtr macwindow, short cticons) {
  61.  
  62.     hdlpaletterecord hpal;
  63.     
  64.     if (!newclearhandle (longsizeof (typaletterecord), (Handle *) &hpal))
  65.         return (nil);
  66.     
  67.     (**hpal).macwindow = macwindow;
  68.     
  69.     (**hpal).cticons = cticons;
  70.     
  71.     (**hpal).palettewidth = (2 * drawinset) + (2 * widthpaletteicon);
  72.     
  73.     return (hpal);
  74.     } /*newpalette*/
  75.     
  76.     
  77. void disposepalette (hdlpaletterecord hpal) {
  78.     
  79.     disposehandle ((Handle) hpal);
  80.     } /*disposepalette*/
  81.     
  82.     
  83. static void centersmallicon (Rect r, short iconlist, short iconnum, boolean flinvert) {
  84.     
  85.     r.top += (r.bottom - r.top - heightsmallicon) / 2;
  86.     
  87.     r.left += (r.right - r.left - widthsmallicon) / 2;
  88.     
  89.     plotsmallicon (r, iconlist, iconnum, flinvert);
  90.     } /*centersmallicon*/
  91.     
  92.     
  93. static void zzz (Rect r) {
  94.     
  95.     bigstring bs;
  96.     
  97.     setstringlength (bs, 0);
  98.     
  99.     pushint (r.top, bs); pushstring ("\p, ", bs);
  100.     
  101.     pushint (r.left, bs); pushstring ("\p, ", bs);
  102.     
  103.     pushint (r.bottom, bs); pushstring ("\p, ", bs);
  104.     
  105.     pushint (r.right, bs); 
  106.     
  107.     DebugStr (bs);
  108.     } /*zzz*/
  109.     
  110.  
  111. void paletteupdate (hdlpaletterecord hpal) {
  112.  
  113.     boolean flbitmap = false;
  114.     Rect r = (**hpal).r;
  115.     short i;
  116.     
  117.     /*flbitmap = openbitmap (r, (**hpal).macwindow);*/
  118.     
  119.     pushbackcolor (lighterblueindex);
  120.     
  121.     EraseRect (&r);
  122.     
  123.     MoveTo (r.right - 1, r.top);
  124.     
  125.     LineTo (r.right - 1, r.bottom);
  126.     
  127.     for (i = 0; i < (**hpal).cticons; i++) {
  128.         
  129.         geticonrect (hpal, i, &r);
  130.         
  131.         if (optionkeydown ())
  132.             zzz (r);
  133.     
  134.         pushbackcolor (whiteindex);
  135.         
  136.         EraseRect (&r);
  137.         
  138.         centersmallicon (r, (**hpal).sicnresource, i, false);
  139.         
  140.         popbackcolor ();
  141.         
  142.         FrameRect (&r);
  143.         
  144.         if ((**hpal).item [i].selected) {
  145.             
  146.             InsetRect (&r, 2, 2);
  147.             
  148.             InvertRect (&r);
  149.             }
  150.         } /*for*/
  151.     
  152.     popbackcolor ();
  153.         
  154.     if (flbitmap)
  155.         closebitmap ((**hpal).macwindow);
  156.     } /*updatepalette*/
  157.     
  158.  
  159. void invalpalette (hdlpaletterecord hpal) {
  160.     
  161.     InvalRect (&(**hpal).r);
  162.     } /*invalpalette*/
  163.     
  164.     
  165. void invalpaletteitem (hdlpaletterecord hpal, short itemnum) {
  166.     
  167.     Rect r;
  168.     
  169.     geticonrect (hpal, itemnum, &r);
  170.         
  171.     InvalRect (&r);
  172.     } /*invalpaletteitem*/
  173.     
  174.     
  175. void palettemousedown (hdlpaletterecord hpal) {
  176.     
  177.     Rect rpalette = (**hpal).r;
  178.     short i;
  179.     
  180.     for (i = 0; i < (**hpal).cticons; i++) {
  181.     
  182.         Rect r;
  183.         
  184.         geticonrect (hpal, i, &r);
  185.         
  186.         if (PtInRect (mousestatus.localpt, &r)) {
  187.             
  188.             (**hpal).itemselected = i;
  189.             
  190.             (*(**hpal).itemhitcallback) ();
  191.             }
  192.         } /*for*/
  193.     
  194.     /*invalpalette (hpal);*/
  195.     } /*palettemousedown*/
  196.     
  197.     
  198. void paletteactivate (hdlpaletterecord hpal, boolean flactivate) {
  199.     } /*paletteactivate*/
  200.     
  201.  
  202. void paletteselectitem (hdlpaletterecord hpal, short itemnum) {
  203.     
  204.     short i;
  205.     
  206.     for (i = 0; i < maxpaletteitems; i++) {
  207.         
  208.         if ((**hpal).item [i].selected)
  209.             invalpaletteitem (hpal, i);
  210.             
  211.         (**hpal).item [i].selected = false;
  212.         } /*for*/
  213.         
  214.     if (!(**hpal).item [itemnum].selected)
  215.         invalpaletteitem (hpal, itemnum);
  216.         
  217.     (**hpal).item [itemnum].selected = true;
  218.     
  219.     /*invalpalette (hpal);*/
  220.     } /*paletteselectitem*/
  221.     
  222.     
  223.